
/******************************************************************************\
|    Title:        	 FIGURE3: Number of switches across the threshold by salary|
|					 quantiles, before and after HLOGA						   |
|    Date:         	 July 2023	                                         	   |
|    Author:         Elisa Wirsching	      							       |
\******************************************************************************/


clear all
set more off, permanently
numlabel, add
set maxvar 32000


use congress_yearly.dta, clear

*------------------------------------------------------------------------------*
*							Switching behavior by quantiles					   *	
*------------------------------------------------------------------------------*

* Note that I care about the LANDING quantile of staffers, i.e. I want
* changes between year t and t+1 (instead of t-1 and t as in the main analysis).

* We therefore need to redefine the treatment period (after HLOGA) and the switching indicator.
* Administrative staff is excluded since they have a cutoff different from the 75% (see manuscript for details).

gen posttreat2 = 0
replace posttreat2 = 1 if year>=2007

xtset stafferid year
gen switchtouncovered2 = F.switchtouncovered_treatment if nonadmin_everyear==1
gen switchtocovered2 = F.switchtocovered_treatment if nonadmin_everyear==1

*****************************************
* Quantiles for switchers into coverage

capture drop groups tocovered
xtile groups = percent_annualpay if percent_annualpay<=0.75 & switchtocovered2!=., n(100)
* share of switchers by quantile
bysort groups posttreat2: egen tocovered = mean(switchtocovered2)

*****************************************
* Quantiles for switchers out of coverage

capture drop groups2 touncovered
xtile groups2 = percent_annualpay if percent_annualpay>0.75 & switchtouncovered2!=., n(11)
* share of switchers by quantile
bysort groups2 posttreat2: egen touncovered = mean(switchtouncovered2)

lab def groups2 1 "75%" 2 "77%" 3 "80%" 4 "82%" 5 "84%" 6 "87%" 7 "90%" 8 "93%" 9 "96%" 10 "97%" 11 "98%", modify
lab val groups2 groups2

lab def groups 82 "47%" 83 "48%" 84 "49%" 85 "50%" 86 "52%" 87 "53%" 88 "54%" 89 "55%" 90 "56%" 91 "58%" 92 "59%" 93 "61%" 94 "62%" 95 "64%" 96 "65%" 97 "67%" 98 "69%" 99 "71%" 100 "73%"
lab val groups groups

*****************************************
* Plot both

cibar switchtocovered2 if groups>=87, over1(posttreat2) over2(groups) barcol(gs6 gs10) graphopts(legend(order(1 "Pre" 2 "Post")) graphregion(color(white)) fxsize(120) ytitle("Share of switches to covered") xlabel(, labsize(vsmall)) name(share_tocovered))

cibar switchtouncovered2 if groups2<11, over1(posttreat2) over2(groups2) barcol(gs6 gs10) graphopts(legend(order(1 "Pre" 2 "Post")) graphregion(color(white)) fxsize(90) ytitle("Share of switches to uncovered") xlabel(, labsize(vsmall)) name(share_touncovered))

grc1leg share_tocovered share_touncovered, graphregion(color(white))




